﻿using FantomNext.Presenters;
using FantomNext.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FantomNext.Factories
{
    public class ShapePresenterFactory
    {
        #region services
        private readonly ShapeFactory _shapeFactory;
        private readonly FantomShapeFactory _fantomShapeFactory;
        public ShapePresenterFactory(ShapeFactory shapeFactory, FantomShapeFactory fantomShapeFactory)
        {
            _shapeFactory = shapeFactory;
            _fantomShapeFactory = fantomShapeFactory;
        }
        #endregion


        #region methods

        /// <summary>
        /// 按照场景图形对象创建图形的 Presenter
        /// </summary>
        /// <param name="shape"></param>
        /// <returns></returns>
        private ShapePresenter CreateCore(Shape shape)
        {
            var model = _fantomShapeFactory.Create(shape);
            return new ShapePresenter(model, shape);
        }

        public ShapePresenter Create(Shape shape)
        {
            var presenter = CreateCore(shape);
            presenter.Load();
            return presenter;
        }

        public async Task<ShapePresenter> CreateAsync(Shape shape)
        {
            var presenter = CreateCore(shape);
            await presenter.LoadAsync();
            return presenter;
        }

        #endregion

    }
}
